package com.sap.sap_mangers.until;

import org.springframework.boot.system.ApplicationHome;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author 谢添
 * @date 2022/8/9 18:56
 */
public class CommonUtils {
    //定义一个文件上传的路径
    public final static String UPLOAD_BOOK_IMAGE_DIRECTORY;

    static {
        //获取文件路径
        ApplicationHome h = new ApplicationHome(CommonUtils.class);
        String bookDirPath = h.getSource().getParentFile().getParentFile().toString();
        UPLOAD_BOOK_IMAGE_DIRECTORY = bookDirPath + "\\src\\main\\resources\\static\\images\\book\\";
    }

    //编写方法，生成一个目录-根据当前日期 年/月
    public static String getUploadBookImageDirectory() {
        return UPLOAD_BOOK_IMAGE_DIRECTORY + new SimpleDateFormat("yyyy\\MM").format(new Date());
    }

    public static String getTimeDirectory() {
        return new SimpleDateFormat("yyyy/MM").format(new Date());
    }
}
